home *** CD-ROM | disk | FTP | other *** search
/ POINT Software Programming / PPROG1.ISO / pascal / swag / dos.swg / 0071_Time Slices.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1994-08-24  |  1.7 KB  |  74 lines

  1. {
  2. Does anyone got any unit/code on giving up time slice under DV or OS/2?
  3. Here they are for DOS, Windows, OS/2, DV and DoubleDos.  You will need
  4. to detect the enviroment first (although none should make the system
  5. hang if it's the wrong enviroment, just be ignored)  The key to good
  6. idle release is finding the right spots to put them.  I have gotten my
  7. door making unit that I created to about 97% idle during pauses and 93%
  8. idle while waiting for keyboard input (with no delay in response - much
  9. better than the typical 12% idle pauses and 8% idle keyboard waits)
  10. Here is how...
  11. }
  12.  
  13. Procedure Sleep(Seconds: Word);
  14. Var
  15.   H,M,S,T,Last: Word;
  16. Begin
  17.   If Seconds = 0 Then Exit;
  18.   If Seconds > 999 Then Seconds := Seconds DIV 1000;
  19.   {incase of caller is thinking milliseconds}
  20.  
  21.   GetTime(H,M,Last,T);
  22.   Repeat
  23.     Repeat
  24.       GetTime(H,M,S,T);
  25.       TimerSlice;
  26.       TimerSlice;
  27.     Until S <> Last;
  28.     Last := S;
  29.     Dec(Seconds);
  30.   Until Seconds = 0;
  31. End;
  32.  
  33. Function GetChar: Char;
  34. Var
  35.   Counter, Span: Byte;
  36.   Done: Boolean;
  37. Begin
  38.   Span := 0;
  39.   Done := False;
  40.   Repeat
  41.     Inc(Counter);
  42.     If Counter > Span Then
  43.       Begin
  44.         Counter := 0;
  45.         If IsChar Then Done := True
  46.         Else If Span < 50 Then Inc(Span);
  47.       End
  48.     Else TimerSlice;
  49.   Until Done;
  50.   If KeyPressedExtended Then GetChar := Readkey
  51.   Else GetChar := RxChar;
  52. End;
  53.  
  54. Procedure TimerSlice;
  55. Begin
  56.   Case SystemEnviroment Of
  57.     DOS4:;
  58.     DOS5,
  59.     WINDOWS,
  60.     OS2: Asm
  61.            MOV AX,$1680
  62.            INT $2F
  63.          End;
  64.     DV: Asm
  65.           MOV AX,$1000
  66.           INT $15
  67.         End;
  68.     DOUBLEDOS: Asm
  69.                  MOV AX,$EE01
  70.                  INT $21
  71.                End;
  72.   End;
  73. End;
  74.